package com.lce.service.impl;

import com.lce.beans.Dept;
import com.lce.beans.Leave;
import com.lce.beans.LeaveType;
import com.lce.beans.User;
import com.lce.dao.ManagerDao;
import com.lce.service.ManagerService;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagerServiceImpl implements ManagerService {

    private SqlSessionTemplate sqlSessionTemplate;

    //setSqlSessionTemplate模板
    @Autowired
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public Dept getDept(int did) {
        ManagerDao managerDao = sqlSessionTemplate.getMapper(ManagerDao.class);
        Dept dept=managerDao.getDept(did);
        return dept;
    }

    @Override
    public List<User> getStaff(int did) {
        ManagerDao managerDao = sqlSessionTemplate.getMapper(ManagerDao.class);
        List<User> ulist = managerDao.getStaff(did);
        return ulist;
    }

    @Override
    public int getDidByUname(String uname) {
        ManagerDao managerDao = sqlSessionTemplate.getMapper(ManagerDao.class);
        int did = managerDao.getDidByUname(uname);
        return did;
    }

    @Override
    public List<LeaveType> getLeaveType() {
        ManagerDao managerDao = sqlSessionTemplate.getMapper(ManagerDao.class);
        List<LeaveType> leaveTypes = managerDao.getLeaveType();
        return leaveTypes;
    }

    @Override
    public void addLeave(Leave leave) {
        ManagerDao managerDao = sqlSessionTemplate.getMapper(ManagerDao.class);
        managerDao.addLeave(leave);
    }
}
